home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / PIL / GribStubImagePlugin.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  51 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import Image
  5. import ImageFile
  6. _handler = None
  7.  
  8. def register_handler(handler):
  9.     global _handler
  10.     _handler = handler
  11.  
  12.  
  13. def _accept(prefix):
  14.     if prefix[0:4] == 'GRIB':
  15.         pass
  16.     return prefix[7] == chr(1)
  17.  
  18.  
  19. class GribStubImageFile(ImageFile.StubImageFile):
  20.     format = 'GRIB'
  21.     format_description = 'GRIB'
  22.     
  23.     def _open(self):
  24.         offset = self.fp.tell()
  25.         if not _accept(self.fp.read(8)):
  26.             raise SyntaxError('Not a GRIB file')
  27.         
  28.         self.fp.seek(offset)
  29.         self.mode = 'F'
  30.         self.size = (1, 1)
  31.         loader = self._load()
  32.         if loader:
  33.             loader.open(self)
  34.         
  35.  
  36.     
  37.     def _load(self):
  38.         return _handler
  39.  
  40.  
  41.  
  42. def _save(im, fp, filename):
  43.     if _handler is None or not hasattr('_handler', 'save'):
  44.         raise IOError('GRIB save handler not installed')
  45.     
  46.     _handler.save(im, fp, filename)
  47.  
  48. Image.register_open(GribStubImageFile.format, GribStubImageFile, _accept)
  49. Image.register_save(GribStubImageFile.format, _save)
  50. Image.register_extension(GribStubImageFile.format, '.grib')
  51.